package main

import (
	"github.com/veandco/go-sdl2/img"
	"github.com/veandco/go-sdl2/sdl"
)

const (
	W = 670
	H = 620
)

func main() {
	sdl.Init(sdl.INIT_EVERYTHING)
	defer sdl.Quit()

	window, _ := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		W, H, sdl.WINDOW_SHOWN)
	defer window.Destroy()

	renderer, _ := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	defer renderer.Destroy()
	renderer.SetDrawColor(128, 128, 128, 255)

	backImage, _ := img.Load("../asserts/image/background.png")
	backTexture, _ := renderer.CreateTextureFromSurface(backImage)
	backImage.Free()
	defer backTexture.Destroy()

	fooImage, _ := img.Load("../asserts/image/foo.png")
	fooImage.SetColorKey(true, sdl.MapRGB(fooImage.Format, 0, 255, 255))
	fooTexture, _ := renderer.CreateTextureFromSurface(fooImage)
	fooImage.Free()
	defer fooTexture.Destroy()

	running := true
	for running {
		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event.(type) {
			case *sdl.QuitEvent:
				println("Quit")
				running = false
				break
			}
		}
		renderer.Clear()

		renderer.Copy(backTexture, nil, nil)

		dst := sdl.Rect{300, 300, 100, 100}
		renderer.Copy(fooTexture, nil, &dst)

		renderer.Present()
		sdl.Delay(16)
	}
}
